package o;

import androidx.annotation.NonNull;
import java.io.FilterInputStream;
import java.io.IOException;
import java.io.InputStream;

public class aap extends FilterInputStream {
    private int ˎ = Integer.MIN_VALUE;

    public aap(@NonNull InputStream inputStream) {
        super(inputStream);
    }

    public synchronized void mark(int i) {
        super.mark(i);
        this.ˎ = i;
    }

    public int read() throws IOException {
        if (ˏ(1) == -1) {
            return -1;
        }
        int read = super.read();
        ˎ(1);
        return read;
    }

    public int read(@NonNull byte[] bArr, int i, int i2) throws IOException {
        int ˏ = (int) ˏ((long) i2);
        if (ˏ == -1) {
            return -1;
        }
        int read = super.read(bArr, i, ˏ);
        ˎ((long) read);
        return read;
    }

    public synchronized void reset() throws IOException {
        super.reset();
        this.ˎ = Integer.MIN_VALUE;
    }

    public long skip(long j) throws IOException {
        long ˏ = ˏ(j);
        if (ˏ == -1) {
            return 0;
        }
        ˏ = super.skip(ˏ);
        ˎ(ˏ);
        return ˏ;
    }

    public int available() throws IOException {
        if (this.ˎ == Integer.MIN_VALUE) {
            return super.available();
        }
        return Math.min(this.ˎ, super.available());
    }

    private long ˏ(long j) {
        if (this.ˎ == 0) {
            return -1;
        }
        if (this.ˎ == Integer.MIN_VALUE || j <= ((long) this.ˎ)) {
            return j;
        }
        return (long) this.ˎ;
    }

    private void ˎ(long j) {
        if (this.ˎ != Integer.MIN_VALUE && j != -1) {
            this.ˎ = (int) (((long) this.ˎ) - j);
        }
    }
}
